

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:flutter/widgets.dart';


void main(List<String> args) {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Tabs(),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int  currentIndex= 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("flutter demo"),
        ),
        body: Homepage(this.currentIndex),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: currentIndex,
          iconSize: 35.0,
          fixedColor: Colors.red,
          type: BottomNavigationBarType.fixed, //底部可以有多个按钮
          onTap: (index){
            print(index);
            setState(() {
              this.currentIndex = index;
            });
          },
          items:[
            BottomNavigationBarItem(
              icon: Image.network(
                "http://p1.meituan.net/200.0/deal/74e45cd53b2f33937c3d058d325354d114273.jpg@95_0_250_250a%7C267h_267w_2e_100Q",height:25.0,width: 25.0,fit: BoxFit.cover,),
              title: Text("123")
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text("123")
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text("123")
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text("123")
            ),
          ]
        ),
      );
  }
}


class Homepage extends StatefulWidget {
  final int initvalue;
  Homepage(this.initvalue,{Key key}) : super(key: key);

  @override
  _HomepageState createState() => _HomepageState();
}

class _HomepageState extends State<Homepage> {
  int countNmuber = 1;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Chip(
          label: Text("$countNmuber"),
        ),
        RaisedButton(
          child: Text("点我${widget.initvalue}"),
          onPressed: (){
            setState(() {
              this.countNmuber ++;
            });
          },
        )
      ],
    );
  }
}

